home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / libogg / libvorbis-1.0rc3 / lib / codebook.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  5.7 KB  |  165 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
  4.  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
  5.  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6.  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  *                                                                  *
  11.  ********************************************************************
  12.  
  13.  function: basic shared codebook operations
  14.  last mod: $Id: codebook.h,v 1.10 2001/12/20 01:00:26 segher Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #ifndef _V_CODEBOOK_H_
  19. #define _V_CODEBOOK_H_
  20.  
  21. #include <ogg/ogg.h>
  22.  
  23. /* This structure encapsulates huffman and VQ style encoding books; it
  24.    doesn't do anything specific to either.
  25.  
  26.    valuelist/quantlist are nonNULL (and q_* significant) only if
  27.    there's entry->value mapping to be done.
  28.  
  29.    If encode-side mapping must be done (and thus the entry needs to be
  30.    hunted), the auxiliary encode pointer will point to a decision
  31.    tree.  This is true of both VQ and huffman, but is mostly useful
  32.    with VQ.
  33.  
  34. */
  35.  
  36. typedef struct static_codebook{
  37.   long   dim;            /* codebook dimensions (elements per vector) */
  38.   long   entries;        /* codebook entries */
  39.   long  *lengthlist;     /* codeword lengths in bits */
  40.  
  41.   /* mapping ***************************************************************/
  42.   int    maptype;        /* 0=none
  43.                 1=implicitly populated values from map column 
  44.                 2=listed arbitrary values */
  45.  
  46.   /* The below does a linear, single monotonic sequence mapping. */
  47.   long     q_min;       /* packed 32 bit float; quant value 0 maps to minval */
  48.   long     q_delta;     /* packed 32 bit float; val 1 - val 0 == delta */
  49.   int      q_quant;     /* bits: 0 < quant <= 16 */
  50.   int      q_sequencep; /* bitflag */
  51.  
  52.   long     *quantlist;  /* map == 1: (int)(entries^(1/dim)) element column map
  53.                map == 2: list of dim*entries quantized entry vals
  54.             */
  55.  
  56.   /* encode helpers ********************************************************/
  57.   struct encode_aux_nearestmatch *nearest_tree;
  58.   struct encode_aux_threshmatch  *thresh_tree;
  59.   struct encode_aux_pigeonhole  *pigeon_tree;
  60.  
  61.   int allocedp;
  62. } static_codebook;
  63.  
  64. /* this structures an arbitrary trained book to quickly find the
  65.    nearest cell match */
  66. typedef struct encode_aux_nearestmatch{
  67.   /* pre-calculated partitioning tree */
  68.   long   *ptr0;
  69.   long   *ptr1;
  70.  
  71.   long   *p;         /* decision points (each is an entry) */
  72.   long   *q;         /* decision points (each is an entry) */
  73.   long   aux;        /* number of tree entries */
  74.   long   alloc;       
  75. } encode_aux_nearestmatch;
  76.  
  77. /* assumes a maptype of 1; encode side only, so that's OK */
  78. typedef struct encode_aux_threshmatch{
  79.   float *quantthresh;
  80.   long   *quantmap;
  81.   int     quantvals; 
  82.   int     threshvals; 
  83. } encode_aux_threshmatch;
  84.  
  85. typedef struct encode_aux_pigeonhole{
  86.   float min;
  87.   float del;
  88.  
  89.   int  mapentries;
  90.   int  quantvals;
  91.   long *pigeonmap;
  92.  
  93.   long fittotal;
  94.   long *fitlist;
  95.   long *fitmap;
  96.   long *fitlength;
  97. } encode_aux_pigeonhole;
  98.  
  99. typedef struct decode_aux{
  100.   long   *tab;
  101.   int    *tabl;
  102.   int    tabn;
  103.  
  104.   long   *ptr0;
  105.   long   *ptr1;
  106.   long   aux;        /* number of tree entries */
  107. } decode_aux;
  108.  
  109. typedef struct codebook{
  110.   long dim;           /* codebook dimensions (elements per vector) */
  111.   long entries;       /* codebook entries */
  112.   const static_codebook *c;
  113.  
  114.   float  *valuelist;  /* list of dim*entries actual entry values */
  115.   long   *codelist;   /* list of bitstream codewords for each entry */
  116.   struct decode_aux *decode_tree;
  117.  
  118.   long zeroentry;
  119. } codebook;
  120.  
  121. extern void vorbis_staticbook_clear(static_codebook *b);
  122. extern void vorbis_staticbook_destroy(static_codebook *b);
  123. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  124. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  125. extern void vorbis_book_clear(codebook *b);
  126.  
  127. extern float *_book_unquantize(const static_codebook *b);
  128. extern float *_book_logdist(const static_codebook *b,float *vals);
  129. extern float _float32_unpack(long val);
  130. extern long   _float32_pack(float val);
  131. extern int  _best(codebook *book, float *a, int step);
  132. extern int _ilog(unsigned int v);
  133. extern long _book_maptype1_quantvals(const static_codebook *b);
  134.  
  135. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  136. extern long vorbis_book_codeword(codebook *book,int entry);
  137. extern long vorbis_book_codelen(codebook *book,int entry);
  138.  
  139.  
  140.  
  141. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  142. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  143.  
  144. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  145. extern int vorbis_book_errorv(codebook *book, float *a);
  146. extern int vorbis_book_encodev(codebook *book, int best,float *a, 
  147.                    oggpack_buffer *b);
  148. extern int vorbis_book_encodevs(codebook *book, float *a, oggpack_buffer *b,
  149.                 int step,int stagetype);
  150.  
  151. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  152. extern long vorbis_book_decodevs_add(codebook *book, float *a, 
  153.                      oggpack_buffer *b,int n);
  154. extern long vorbis_book_decodev_set(codebook *book, float *a, 
  155.                     oggpack_buffer *b,int n);
  156. extern long vorbis_book_decodev_add(codebook *book, float *a, 
  157.                     oggpack_buffer *b,int n);
  158. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  159.                      long off,int ch, 
  160.                     oggpack_buffer *b,int n);
  161.  
  162.  
  163.  
  164. #endif
  165.